package Manage;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Info.BaogaoBI;
import Util.DatabaseConn;

public class BaogaoBM {
	private Connection conn;
	private ResultSet rs;
	private PreparedStatement pstmt;
	public List<BaogaoBI> findAll() {
		List<BaogaoBI> bbs = new ArrayList<BaogaoBI>();
		Connection conn = null;
		try {
			 conn = DatabaseConn.getConnection();
		     pstmt = conn.prepareStatement("select * from baogaob");	     
		     rs = pstmt.executeQuery();
		     while(rs.next()){
				int id =  rs.getInt("id");
				String name = rs.getString("name");
				String age = rs.getString("age");
				String sex = rs.getString("sex");
				String card = rs.getString("card");
				String num = rs.getString("num");
				String type = rs.getString("type");
				String shengao = rs.getString("shengao");
				String tizhong = rs.getString("tizhong");
				String sizhi = rs.getString("sizhi");
				String jizhu = rs.getString("jizhu");
				String jiazhuangxian = rs.getString("jiazhuangxian");
				String xuechanggui = rs.getString("xuechanggui");
				String yijian = rs.getString("yijian");
				String time = rs.getString("time");
		     	BaogaoBI bb = new BaogaoBI(id, name, age, sex, card, num, type, shengao, tizhong, sizhi, jizhu, jiazhuangxian, xuechanggui, yijian, time);
		     	bbs.add(bb);
			}
		} catch (Exception e) {

		} finally {
			DatabaseConn.closeConn(conn);
		}
		return bbs;
	}
	
	public BaogaoBI Find(String card) {
		new DatabaseConn();
		BaogaoBI bb = null;
		try {
			conn = DatabaseConn.getConnection();
			pstmt = conn.prepareStatement("select * from baogaob where card=?");
			pstmt.setString(1, card);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				int id =  rs.getInt("id");
				String name = rs.getString("name");
				String age = rs.getString("age");
				String sex = rs.getString("sex");
				String num = rs.getString("num");
				String type = rs.getString("type");
				String shengao = rs.getString("shengao");
				String tizhong = rs.getString("tizhong");
				String sizhi = rs.getString("sizhi");
				String jizhu = rs.getString("jizhu");
				String jiazhuangxian = rs.getString("jiazhuangxian");
				String xuechanggui = rs.getString("xuechanggui");
				String yijian = rs.getString("yijian");
				String time = rs.getString("time");
		     	bb = new BaogaoBI(id, name, age, sex, card, num, type, shengao, tizhong, sizhi, jizhu, jiazhuangxian, xuechanggui, yijian, time);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DatabaseConn.closeConn(conn);
		}
		return bb;
	}
}
